package com.hzsk.lisence.controller;

import com.github.pagehelper.PageInfo;
import com.hzsk.lisence.entity.EmDeviceRelationEntity;
import com.hzsk.lisence.entity.EmProducePlanEntity;
import com.hzsk.lisence.entity.EmSoftwareRelationEntity;
import com.hzsk.lisence.entity.request.NcProduceRequest;
import com.hzsk.lisence.entity.response.IncResponce;
import com.hzsk.lisence.entity.response.NcProduceDetail;
import com.hzsk.lisence.service.EmRelationBindService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description :
 * @Date : 2024/8/21
 * @Author : ChenJin
 * @Version : v1.0.0
 **/
@CrossOrigin
@RestController
@RequestMapping("/api/lisence/relation")
public class EmRelationBindController {
    
    @Resource
    private EmRelationBindService emRelationBindService;

    @PostMapping("/sync-software")
    @ApiOperation(value = "软件关系绑定")
    public IncResponce syncSoftware(@RequestBody EmSoftwareRelationEntity emSoftwareRelationEntity){
        IncResponce incResponce = new IncResponce();
        try {
            Boolean result = emRelationBindService.syncSoftwareRelation(emSoftwareRelationEntity);
            incResponce.setData(result);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }

    @PostMapping("/sync-device")
    @ApiOperation(value = "产品关系绑定")
    public IncResponce syncDevice(@RequestBody EmDeviceRelationEntity emDeviceRelationEntity){
        IncResponce incResponce = new IncResponce();
        try {
            Boolean result = emRelationBindService.syncDeviceRelation(emDeviceRelationEntity);
            incResponce.setData(result);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }

    @PostMapping("/get-nc-produce-detail")
    @ApiOperation(value = "数控装置制作详情")
    public IncResponce getNcProduceDetail(@RequestBody NcProduceRequest ncProduceRequest){
        IncResponce incResponce = new IncResponce();
        try {
            PageInfo<EmDeviceRelationEntity> ncProduceDetailList = emRelationBindService.getNcProduceList(ncProduceRequest);
            incResponce.setData(ncProduceDetailList);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }

    @PostMapping("/update-device-status")
    @ApiOperation(value = "修改数控装置制作状态")
    public IncResponce updateDeviceRelationStatus(@RequestBody EmDeviceRelationEntity emDeviceRelationEntity){
        IncResponce incResponce = new IncResponce();
        try {
            Boolean result = emRelationBindService.updateDeviceRelationStatus(emDeviceRelationEntity);
            incResponce.setData(result);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }
    
    @PostMapping("/update-device")
    @ApiOperation(value = "变更产品绑定关系")
    public IncResponce updateDeviceRelation(@RequestBody EmDeviceRelationEntity emDeviceRelationEntity){
        IncResponce incResponce = new IncResponce();
        try {
            Boolean result = emRelationBindService.updateDeviceRelation(emDeviceRelationEntity);
            incResponce.setData(result);
            incResponce.setCode(0);
        } catch (Exception e) {
            incResponce.setCode(-1);
            incResponce.setErrorMessage(e.getMessage());
            e.printStackTrace();
        }
        return incResponce;
    }
    
}
